#ifndef _RETRO_SELECTOR
#define _RETRO_SELECTOR

namespace Retro
{
  namespace Creator
  {
    namespace Toolbox
    {
      enum SelectorNotify
      {
        SelectorNotifySelection = 0x0001,
        SelectorNotifySpriteType,
        SelectorNotifyTexture,
        SelectorNotifyEdit,
        SelectorNotifyErase,
      };

      enum SelectorColorMode
      {
        ColorTopLeft      = Data::ColorTopLeft,
        ColorTopRight     = Data::ColorTopRight,
        ColorBottomLeft   = Data::ColorBottomLeft,
        ColorBottomRight  = Data::ColorBottomRight,
        ColorLeft,
        ColorRight,
        ColorTop,
        ColorBottom,
        ColorAll,
      };

      class Selector : public GUI::Component
      {
      private:
        struct NumericItem
        {
          Label   label;
          WrapWnd edit;
          WrapWnd scroll;

          VOID  create(
            Selector& iParent,
            INT       iID,
            PCTSTR    iText,
            INT       iMin,
            INT       iMax,
            INT       iIncrement
            );

          VOID  addToLayout(
            LayoutElement* iLayout,
            INT iTextWidth,
            INT iEditWidth
            );
        };

        GUI::TileSelector mTileSelector;
        GUI::ColorPicker  mColorPicker;
        ToolBar           mToolbar;
        ToolBar           mColorbar;
        Slider            mSliderWidth;
        Slider            mSliderHeight;
        Label             mSizeLabel;
        Separator         mSeparator1;
        Separator         mSeparator2;
        NumericItem       mWidth;
        NumericItem       mHeight;
        LayoutElement     mLayout;
        LayoutElement*    mContent;
        LayoutElement*    mLayoutToolbar;
        Data::Resource*   resource;
        Menu              mMenuTool;
        Menu              mMenuSprite;
        Menu              mMenuTexture;
        Menu              mMenuColor;
        Data::SpriteType  mSpriteType;
        HFONT             mFont;
        Gdip::Font        mTextFont;
        Gdip::Font        mHeadingFont;
        Geom::RGBColor    mColors[Data::ColorLast - Data::ColorFirst + 1];
        SelectorColorMode mColorMode;
        BOOL              mNoNotify;

        VOID  initGridBar();
        VOID  updateColor();

      protected:
        virtual VOID  onCreate(Event::WndCreateEvent& iEvent);
        virtual VOID  onDestroy();
        virtual VOID  onSize(Event::SizeEvent& iEvent);
        virtual VOID  onFocus(Event::FocusEvent& iEvent);
        virtual VOID  onPaint();
        virtual VOID  onEraseBackground(Event::EraseBackgroundEvent& iEvent);
        virtual VOID  onNotify(Event::NotifyEvent& iEvent);
        virtual VOID  onCommand(Event::CommandEvent& iEvent);

      public:
        VOID  loadTextures();

        INL GUI::TileTool getTileTool()
        {
          return mTileSelector.getTool();
        }
        VOID  setTileTool(GUI::TileTool iValue);

        INL Geom::Bounds  getSelection()
        {
          switch (mSpriteType)
          {
          case Data::SpriteTexture:
            return mTileSelector.getSelection();
          case Data::SpriteRect:
            return Geom::Bounds::get(
              0,
              0,
              mSliderWidth.getValue(),
              mSliderHeight.getValue());
          }

          return Geom::Bounds::get(0, 0, 0, 0);
        }
        VOID  setSelection(const Geom::Bounds& value)
        {
          switch (mSpriteType)
          {
          case Data::SpriteTexture:
            mTileSelector.setSelection(value);
            break;
          case Data::SpriteRect:
            mSliderWidth.setValue(value.cx);
            mSliderHeight.setValue(value.cy);
            break;
          }
        }

        INLC Geom::RGBColor getColor(Data::ColorIndex iIndex)
        {
          return mColors[iIndex];
        }

        INL SelectorColorMode getColorMode()
        {
          return mColorMode;
        }

        VOID setColorMode(SelectorColorMode iValue);

        INL BOOL  getTileErase()
        {
          return mTileSelector.getErase();
        }
        INL VOID  setTileErase(BOOL value)
        {
          mTileSelector.setErase(value);
        }

        VOID  setTexture(Data::Texture* iValue);
        INL Data::Texture*  getTexture()
        {
          return mTileSelector.getTexture();
        }

        VOID  setSpriteType(Data::SpriteType iValue);
        INL Data::SpriteType getSpriteType()
        {
          return mSpriteType;
        }

        VOID  setResource(Data::Resource* res);
        INL Data::Resource* getResource()
        {
          return resource;
        }

        Selector();
      };
    } // namespace Toolbox
  } // namespace Creator
} // namespace Retro

#endif